
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orgname: '',
    orgurl: '',
    orgid: '',
    list: [],
    isorg: null,
    pageNumber: 1,
    totalPages: 1,
    username: '',
    imgurl: '',
    isParentOrgRw:null,
    show:false,
    isAdministrators:null,
  },
  topages(e) {
    var reportDate = e.currentTarget.dataset.reportdate
    var follow = e.currentTarget.dataset.follow
    if(this.data.isParentOrgRw==0){
      wx.navigateTo({
        url: '/pages/workStatisticsDay/workStatisticsDay?orgid=' + this.data.orgid + '&reportdate=' + reportDate + '&isorg=' + this.data.isorg + '&follow=' + follow + '&orgname=' + this.data.orgname + '&orgurl=' + this.data.orgurl,
      })
    } else if (this.data.isParentOrgRw == 1){
      wx.navigateTo({
        url: '/pages/reportOrg/reportOrg?orgid=' + this.data.orgid + '&reportdate=' + reportDate + '&isorg=' + this.data.isorg + '&follow=' + follow + '&orgname=' + this.data.orgname + '&orgurl=' + this.data.orgurl,
      })
    }
  },
  toexport() {
    wx.navigateTo({
      url: '/pages/workexport/workexport?orgid=' + this.data.orgid + '&isorg=' + this.data.isorg + '&isParentOrgRw=' + this.data.isParentOrgRw,
    })
  },
  tosee() {
    wx.navigateTo({
      url: '/packageA/pages/epidemicSeeNew/epidemicSeeNew?isOrg=' + this.data.isAdministrators + '&id=' + this.data.orgid,
    })
  },
  tosee1(){
    // this.setData({
    //   show: true
    // })
    wx.navigateTo({
      url: '/pages/reportSearch/reportSearch?id=' + this.data.orgid,
    })
  },
  getimg() {
    var that = this
    app.req({
      url: 'wechat/activity/getPictureListByType',
      data: {
        type: 26,
        pageSize: 10,
        pageNumber: 1
      },
      success: function (res) {
        if (res.code == 200) {
          that.setData({
            imgurl: res.data.rows[0].url
          })
        }
      }
    })
  },
  getorg() {
    var that = this
    app.req({
      url: "orgmini/resumptionWork/orgRwStatisticsList",
      data: {
        orgId: that.data.orgid,
        pageNumber: that.data.pageNumber,
        pageSize: 10,
      },
      success: function (res) {
        if (200 == res.code) {
          if (that.data.pageNumber == 1) {
            that.setData({
              list: res.data.rows
            })
          } else {
            that.setData({
              list: that.data.list.concat(res.data.rows)
            })
          }
          that.setData({
            totalPages: res.data.totalPages
          })
        }
      }
    });
  },
  getpersonal() {
    var that = this
    app.req({
      noLoading: true,
      url: "orgmini/resumptionWork/reportOrgList",
      data: {
        orgId: that.data.orgid,
        pageNumber: that.data.pageNumber,
        pageSize: 10,
      },
      success: function (res) {
        if (200 == res.code) {
          if (that.data.pageNumber == 1) {
            that.setData({
              list: res.data.rows
            })
          } else {
            that.setData({
              list: that.data.list.concat(res.data.rows)
            })
          }
          that.setData({
            totalPages: res.data.totalPages
          })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      isorg: options.isorg
    })
    if (options.isorg == 1) {
      this.setData({
        orgid: options.orgid,
        orgname: options.orgname,
        orgurl: options.orgurl,
        isParentOrgRw: options.isParentOrgRw,
        isAdministrators: options.isAdministrators
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.getimg()
    if (that.data.isParentOrgRw == 0) {
      that.getorg()
    } else if (that.data.isParentOrgRw == 1) {
      that.getpersonal()
    }
    app.getUserInfo(function (userInfo) {
      that.setData({
        username: userInfo.realName
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (that.data.totalPages > that.data.pageNumber) {
      that.setData({
        pageNumber: that.data.pageNumber + 1
      })
      if (that.data.isParentOrgRw == 0) {
        that.getorg()
      } else if (that.data.isParentOrgRw == 1) {
        that.getpersonal()
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var title = ''
    var url = ''
    if (this.data.isorg == 1) {
      title = this.data.orgname + '邀请你用一起来往进行复工打卡'
      url = '/pages/orgHome/orgHome?id=' + this.data.orgid
    } else if (this.data.isorg == 0) {
      title = this.data.username + '邀请你用一起来往进行复工打卡'
      url = '/packageA/pages/epidemicSeeNew/epidemicSeeNew?isorg=' + this.data.isorg + '&id=' + wx.getStorageSync('uid')
    }
    return {
      title: title,
      imageUrl: this.data.imgurl,
      path: url
    }
  }
})